//
//  WCSymbol.m
//  WabbitCode
//
//  Created by William Towe on 3/27/09.
//  Copyright 2009 Revolution Software. All rights reserved.
//

#import "WCSymbol.h"
#import "WCTextFile.h"


@implementation WCSymbol
- (void)dealloc {
	[_name release];
	[super dealloc];
}

@synthesize type=_type,name=_name,lineNumber=_lineNumber,textFile=_textFile;

@dynamic symbolTypeAsString;
- (NSString *)symbolTypeAsString {
	switch (_type) {
		case WCSTypeEquate:
			return NSLocalizedString(@"Equate",@"Equate");
		case WCSTypeLabel:
			return NSLocalizedString(@"Label",@"Label");
		case WCSTypeMacro:
			return NSLocalizedString(@"Macro",@"Macro");
		case WCSTypeDefine:
			return NSLocalizedString(@"Define",@"Define");
		default:
			return nil;
	}
}

@dynamic fileAndLocation;
- (NSString *)fileAndLocation {
	return [NSString stringWithFormat:@"%@:%u", [_textFile name], _lineNumber+1];
}

@dynamic icon;
- (NSImage *)icon {
	switch (_type) {
		case WCSTypeEquate:
			return [NSImage imageNamed:@"EquatesAutocomplete"];
		case WCSTypeLabel:
			return [NSImage imageNamed:@"LabelAutocomplete"];
		case WCSTypeMacro:
		case WCSTypeDefine:
			return [NSImage imageNamed:@"PreProcessorAutocomplete"];
		default:
			return nil;
	}
}

- (id)initWithSymbolType:(WCSType)type name:(NSString *)name file:(WCTextFile *)file lineNumber:(NSUInteger)lineNumber; {
	if (!(self = [super init]))
		return nil;
	
	_type = type;
	_name = [name retain];
	_textFile = file;
	_lineNumber = lineNumber;
	
	return self;
}

+ (WCSymbol *)symbolWithSymbolType:(WCSType)type name:(NSString *)name file:(WCTextFile *)file lineNumber:(NSUInteger)lineNumber; {
	return [[[[self class] alloc] initWithSymbolType:type name:name file:file lineNumber:lineNumber] autorelease];
}
@end
